package com.ruima.study.arithmetic.law;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * <p></p>
 * <p>
 * <p>Copyright (c) 2024/11/22 9:35, 科大讯飞 All Rights Reserve</p>
 *
 * @author ruima6
 * @version [V1.0]
 */
public class Demo1 {

    public static void main(String[] args) {
        int[][] arr = {{1,2,0,4,5,6},{7,8,9,0,11,12},{13,14,15,16,17,18},{19,20,21,22,23,24}};
        toZero(arr);
    }

    public static void toZero(int[][] arr){
        List<Integer> listI = new ArrayList<>();
        List<Integer> listJ = new ArrayList<>();

        int lengthI = arr.length;
        int lengthJ = arr[0].length;
        for (int i = 0; i < arr.length; i++) {
            int length = arr[i].length;
            for (int j = 0; j < length; j++) {
                if (arr[i][j] == 0){
                    listI.add(i);
                    listJ.add(j);
                }
            }
        }

        for (int i = 0; i < listI.size(); i++) {
            Integer indexI = listI.get(i);
            for (int j = 0; j < lengthJ; j++) {
                arr[indexI][j] = 0;
            }
        }

        for (int i = 0; i < listJ.size(); i++) {
            Integer indexJ = listJ.get(i);
            for (int j = 0; j < lengthI; j++) {
                arr[j][indexJ] = 0;
            }
        }
        System.out.println(arr);
    }



}
